import { preget, get, getSuo } from "./request";

var baseurl = "https://api.clicli.us";

// banner
export function recommended(data) {
  var params = {
    status: "public",
    sort: "新番",
    tag: "",
    uid: "",
    page: 1,
    pageSize: 10,
    ...data
  };
  return preget(`${baseurl}/posts`, params);
}

// 新番列表
export function newPosts(data) {
  var params = {
    status: "nowait",
    sort: "新番",
    page: 1,
    pageSize: 100,
    ...data
  };
  return preget(`${baseurl}/posts`, params);
}

// 视频资源
export function getVideos(pid) {
  var params = {
    pid,
    page: 1,
    pageSize: 150
  };
  return get(`${baseurl}/videos`, params);
}

// 评论
export function getComments(pid) {
  var params = {
    pid,
    page: 1,
    pageSize: 100
  };
  return get(`${baseurl}/comments`, params);
}

// 介绍
export function getPost(id) {
  return preget(`${baseurl}/post/${id}`);
}

// 根据地址获取真实链接
export function getRealUrl(url) {
  var params = {
    url
  };
  return get("https://jx.clicli.us/jx", params);
}

// 发现
export function getexplore(type, data) {
  if(type === 'search') {
    return get(`${baseurl}/search/posts`, {
      page: 1,
      pageSize: 30,
      ...data
    }).then(res => {
      if(res.posts) {
        res.posts.forEach(post => {
          post.img = getSuo(post.content);
        });
        return res;
      }
    })
  } else {
    var params = {
      status: "public",
      sort: "原创",
      tag: "",
      uid: "",
      page: 1,
      pageSize: 30,
      ...data
    };
    return get(`${baseurl}/posts`, params).then(res => {
      if(res.posts) {
        res.posts.forEach(post => {
          post.img = getSuo(post.content);
        });
        return res;
      }
    })
  }
}